<template>
  <k-form-design ref='kfd' 
    title="设置表达类型"
    @save="handleSave" 
    :toolbars="['save']"
    :fields="['input', 'date', 'number']"
  />
</template>
<script>
import { UpdataTaskTwo } from '../../api/school'
export default {
  name: 'UpdataForm',
  data () {
    return {
      jsonData: {},
      id: 0,
    }
  },
  methods: {
    importData () {
      this.$refs.kfd.handleSetData(this.jsonData)
    },
    handleSave(values) {
      if(!this.id == 0) {
          let value = {}
          values.users_id = localStorage.getItem('users_id')
          value.id = this.id
          value.forms = values
          UpdataTaskTwo(value).then(res => {
          this.$message.success('更新成功')
          this.$router.push('/task/tasklist/index')
        })
      } else {
          this.$message.info('当前为修改表单,不可直接添加')
      }
      console.log(values);
    }
  },
  mounted () {
    let data = JSON.parse(this.$route.query.data)
    this.id = data.id
    this.jsonData = data.forms
    console.log('--------------data-------------', data)
    this.importData()
  }
}
</script>